//
//  device_retriever_macos.cpp
//  testpcap
//
//  Created by bugforever on 1/10/15.
//  Copyright (c) 2015 bugforever. All rights reserved.
//

#include "device_retriever_libpcap.h"

#include "../../ThirdParty/libpcap-1.6.2/pcap.h"

device_retriever_libpcap::device_retriever_libpcap()
{
    ;
}

device_retriever_libpcap::~device_retriever_libpcap()
{
    ;
}

bool device_retriever_libpcap::get_device_list(std::vector< device_info * > ** pptr_list)
{
    char errbuf[PCAP_ERRBUF_SIZE];
    pcap_if_t * ptr_devices = 0;
    
    int ret = pcap_findalldevs( &ptr_devices , errbuf );
    
    if( ret == -1 )
        return false;
    
    pcap_if_t * ptr_current = ptr_devices;
    
    while( ptr_current )
    {
        device_info * ptr_info = new device_info();
        
        ptr_info->set_name(ptr_current->name);
        ptr_info->set_description(ptr_current->description);
        
        m_device_list.push_back( ptr_info );
        
        ptr_current = ptr_current->next;
    }
    
    
    pcap_freealldevs( ptr_devices );
    
    *pptr_list = &m_device_list;
    
    return true;
}